package com.tianqu.tms.www.transfer.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferProcessHistory;
import com.tianqu.tms.www.transfer.viewhelper.CheckConfirmViewHelper;

public class PNCInputResultController extends TmsController {
	private Logger logger = Logger
	.getLogger(PNCInputResultController.class);
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = getTxController();
		try {
			controller.begin();
			CheckConfirmViewHelper view = (CheckConfirmViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
			String serial = view.getSerial();
			TmsUserProfile profile = uc.getUserProfile();
			TransferAcceptedInfo accept = new TransferAcceptedInfo();
			accept = accept.getAcceptInfoBySerialAndCarLicense(serial,"",0);
			accept.setLz_printUserId(profile.getUniqueId());
			accept.setSerial(serial);
			accept.setLz_printnum(accept.getLz_printnum()+1);
			accept.updateTransferLzPrintNumBySerial(accept);
			
			TransferProcessHistory history = new TransferProcessHistory();
			history.setSerial(view.getSerial());
			history.setBusinessType(35);
			history.setInsertUserId(profile.getUniqueId());
			history.setReason("");
			history.insertHisInfoAtAssess(history);
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
	}
}
